import Vue from 'vue'
import Router from 'vue-router'
// in development env not use Lazy Loading,because Lazy Loading too many pages will cause webpack hot update too slow.so only in production use Lazy Loading
/* layout */
import Layout from '../views/layout/Layout'
import empty from '../views/layout/empty'

const _import = require('./_import_' + process.env.NODE_ENV)
Vue.use(Router)

// 所有权限通用路由表
// 如首页和登陆页和一些不用权限的公用页面
export const constantRouterMap = [
  {path: '/login', component: _import('login/index'), hidden: true},
  {path: '/404', component: _import('404'), hidden: true},
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    name: '首页',
    hidden: true,
    children: [{
      path: 'dashboard', component: _import('dashboard/index')
    }]
  },

];

// web 路由  不需要登陆的路由
const webRouterMap = [
  {
    path: '/screen',
    name: 'screen',
    redirect: '/screen/technology',
    hideChild:true,
    meta: {title: '数据可视化展示', icon: 'tree',target:'_blank',web:true},
    component: _import('screen/Index'),
    children:[
      {
        path: 'technology',
        name: 'technology',
        meta: {title: '技术动态', icon: 'tree'},
        component: _import('screen/pages/Technology')
      },
      {
        path: 'organization',
        name: 'organization',
        meta: {title: '机构动态', icon: 'tree'},
        component:_import('screen/pages/Organization')
      },
      {
        path: 'expert',
        name: 'expertpage',
        meta: {title: '专家动态', icon: 'tree'},
        component:_import('screen/pages/Expert')
      },
      {path: '*', redirect: '/404', hidden: true}
    ]
  },
];
webRouterMap.forEach(routerItem => {
  constantRouterMap.push(routerItem)
});

// 实例化vue的时候只挂载constantRouter
export default new Router({
  // mode: 'history', //后端支持可开
  scrollBehavior: () => ({y: 0}),
  routes: constantRouterMap
})




//异步挂载的路由
//动态需要根据权限加载的路由表

//这里我们根据 vue-router官方推荐 的方法通过meta标签来标示改页面能访问的权限有哪些。如meta: { role: ['admin','super_editor'] }表示该页面只有admin和超级编辑才能有资格进入。
// export const asyncRouterMap = [
//   {
//     path: '/dashboard',
//     component: Layout,
//     redirect: '/dashboard',
//     children: [
//       {
//         path: 'dashboard',
//         name: '',
//         component: _import('dashboard/index'),
//         meta: {title: '首页', icon: 'table'},
//         menu: 'dashboard'
//       },
//     ]
//   },
//   {
//     path: '/user',
//     component: Layout,
//     redirect: '/user/',

//     children: [
//       {
//         path: 'role',
//         name: '权限管理',
//         component: _import('user/role'),
//         meta: {title: '权限管理', icon: 'password'},
//         menu: 'role'
//       },
//     ]
//   },
//   {
//     path: '/staff',
//     component: Layout,
//     redirect: '/staff/staff',
//     name: 'staff',
//     meta: {title: '员工管理', icon: 'tree'},
//     children: [
//       {
//         path: '/staff/staff', name: '员工管理', component: _import('staff/staff'), menu: 'staff',
//         children:[
//           {
//             path: 'test', name: '人员管理', component: _import('staff/test'), meta: {title: '人员管理', icon: 'user'}, menu: 'staff',
//           }
//         ]
//       },

//     ]
//   },
//   {
//     path: '/department',
//     component: Layout,
//     redirect: '/department/department',
//     children: [
//       {
//         path: 'department',
//         name: '部门管理',
//         component: _import('department/department'),
//         meta: {title: '部门管理', icon: 'example'},
//         menu: 'department'
//       },
//     ]
//   },
//   {
//     path: '/position',
//     name: 'positions',
//     component: Layout,
//     redirect: '/position/position',
//     children: [
//       {
//         path: 'position',
//         name: '岗位管理',
//         component: _import('position/position'),
//         meta: {title: '岗位管理', icon: 'example'},
//         menu: 'position'
//       },
//     ]
//   },
//   {
//     path: '/template',
//     name: 'templates',
//     component: Layout,
//     redirect: '/template/temp',
//     children: [
//       {
//         path: 'temp',
//         name: '模版管理',
//         component: _import('datatemp/template'),
//         meta: {title: '报告模板设置', icon: 'example'},
//         menu: 'position'
//       },
//     ]
//   },
//   {
//     path: '/datagather',
//     component: Layout,
//     redirect: '/datagather/author',
//     name: 'datagather',
//     meta: {title: '数据采集', icon: 'tree'},
//     children: [
//       {
//         path: 'author',
//         name: '专家',
//         component: _import('datagather/author'),
//         meta: {title: '专家', icon: 'example'},
//         menu: 'position'
//       },
//       {
//         path: 'article',
//         name: '技术动态',
//         component: _import('datagather/article'),
//         meta: {title: '技术动态', icon: 'example'},
//         menu: 'position'
//       },
//       {
//         path: 'hotword',
//         name: '热词',
//         component: _import('datagather/hotword'),
//         meta: {title: '热词', icon: 'example'},
//         menu: 'position'
//       },
//       {
//         path: 'organization',
//         name: '机构',
//         component: _import('datagather/organization'),
//         meta: {title: '机构', icon: 'example'},
//         menu: 'position'
//       },
//       {
//         path: 'paper',
//         name: '论文',
//         component: _import('datagather/paper'),
//         meta: {title: '论文', icon: 'example'},
//         menu: 'position'
//       },
//       {
//         path: 'patent',
//         name: '专利',
//         component: _import('datagather/patent'),
//         meta: {title: '专利', icon: 'example'},
//         menu: 'position'
//       },
//     ]
//   },
//   {
//     path: '/parameters',
//     component: Layout,
//     redirect: '/parameters/parameters',

//     children: [
//       {
//         path: 'role',
//         name: '爬虫参数设置',
//         component: _import('parameters/parameters'),
//         meta: {title: '爬虫参数设置', icon: 'password'},
//         menu: 'role'
//       },
//     ]
//   },
//   {
//     path: '/logmanagement',
//     name: 'logmanagement',
//     component: Layout,
//     redirect: '/logmanagement/logs',
//     children: [
//       {
//         path: 'temp',
//         name: '日志管理',
//         component: _import('logmanagement/logs'),
//         meta: {title: '日志管理', icon: 'password'},
//         menu: 'position'
//       },
//     ]
//   },
//   {
//     path: '/spider',
//     component: Layout,
//     redirect: '/spider',
//     meta: {title: '爬虫管理', icon: 'password'},
//     children: [
//       {
//         path: 'keyword', name: '关键词管理', component: _import('spider/keyword'), meta: {title: '关键词管理', icon: 'user'}, menu: 'spider',
//       },
//       {
//         path: 'stopword', name: '停用词管理', component: _import('spider/stopword'), meta: {title: '停用词管理', icon: 'user'}, menu: 'spider',
//       }
//     ]
//   },
//   {
//     path: '/data_dic',
//     component: Layout,
//     redirect: '/data_dic/data_dic',

//     children: [
//       {
//         path: 'role',
//         name: '数据字典',
//         component: _import('data_dic/data_dic'),
//         meta: {title: '数据字典', icon: 'password'},
//         menu: 'role'
//       },
//     ]
//   },

//   {
//     path: '/exportscreen',
//     name: 'exportscreen',
//     redirect: '/exportscreen/page',
//     hideChild:true,
//     meta: {title: '数据导出', icon: 'tree',target:'_blank'},
//     component: _import('exportScreen/exportlayout/layout'),
//     children:[
//       {
//         path: 'page',
//         name: 'exportscreenpage1',
//         meta: {title: '数据导出页面1', icon: 'tree'},
//         component: _import('exportScreen/page/view'),
//       },
//     ]
//   },
//   {path: '*', redirect: '/404', hidden: true}
// ]


export const asyncRouterMap = [
  {
    path: '/dashboard',
    component: Layout,
    redirect: '/dashboard',
    children: [
      {
        path: 'dashboard',
        name: '',
        component: _import('dashboard/index'),
        meta: {title: '首页', icon: 'table'},
        menu: 'dashboard'
      },
    ]
  },
  {
    path: '/sys_manager',
    component: Layout,
    redirect: '/dashboard',
    name: '',
    meta: {title: '系统管理', icon: 'table'},
    children: [
      {
        path: 'logs',
        name: '日志管理',
        component: _import('sys_manager/logs'),
        meta: {title: '日志管理', icon: 'password'}
      },
      {
        path: 'data_dic',
        name: '数据字典',
        component: _import('sys_manager/data_dic'),
        meta: {title: '数据字典', icon: 'password'}
      },
      {
        path: 'role',
        name: '权限管理',
        component: _import('sys_manager/role'),
        meta: {title: '权限管理', icon: 'password'}
      },
      {
        path: 'test', 
        name: '用户管理', 
        component: _import('sys_manager/staff'), 
        meta: {title: '用户管理', icon: 'user'}
      },
      {
        path: 'department',
        name: '部门管理',
        component: _import('sys_manager/department'),
        meta: {title: '部门管理', icon: 'example'}
      },
      {
        path: 'position',
        name: '角色管理',
        component: _import('sys_manager/position'),
        meta: {title: '角色管理', icon: 'example'},
        menu: 'position'
      }
    ]
  },
  {
    path: '/data_manager',
    component: Layout,
    redirect: '/dashboard',
    name: '',
    meta: {title: '数据管理', icon: 'table'},
    children: [
      {
        path: '/datagather',
        component: empty,
        redirect: '/dashboard',
        name: 'datagather',
        meta: {title: '采集数据查询', icon: 'tree'},
        children: [
          {
            path: 'author',
            name: '专家',
            component: _import('data_manager/datagather/author'),
            meta: {title: '专家', icon: 'example'}
          },
          {
            path: 'article',
            name: '技术动态',
            component: _import('data_manager/datagather/article'),
            meta: {title: '技术动态', icon: 'example'}
          },
          {
            path: 'hotword',
            name: '热词',
            component: _import('data_manager/datagather/hotword'),
            meta: {title: '热词', icon: 'example'}
          },
          {
            path: 'organization',
            name: '机构',
            component: _import('data_manager/datagather/organization'),
            meta: {title: '机构', icon: 'example'}
          },
          {
            path: 'paper',
            name: '论文',
            component: _import('data_manager/datagather/paper'),
            meta: {title: '论文', icon: 'example'}
          },
          {
            path: 'patent',
            name: '专利',
            component: _import('data_manager/datagather/patent'),
            meta: {title: '专利', icon: 'example'}
          },
        ]
      },
      {
        path: 'role',
        name: '采集参数设置',
        component: _import('data_manager/parameters'),
        meta: {title: '爬虫参数设置', icon: 'password'}
      },
      {
        path: 'keyword', 
        name: '关键词管理', 
        component: _import('data_manager/keyword'), 
        meta: {title: '关键词管理', icon: 'user'}
      },
      {
        path: 'stopword', name: '停用词管理', 
        component: _import('data_manager/stopword'), 
        meta: {title: '停用词管理', icon: 'user'}
      }
    ]
  },
  {
    path: '/port_manager',
    component: Layout,
    redirect: '/dashboard',
    name: '',
    meta: {title: '报告管理', icon: 'table'},
    children: [
      {
        path: 'template',
        name: '报告模板设置',
        component: _import('port_manager/template'),
        meta: {title: '报告模板设置', icon: 'example'}
      }
    ]
  },
  {path: '*', redirect: '/404', hidden: true}
]